package com.pswv2.backstage.keyword.imp;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.pswv2.backstage.keyword.service.KWordService;
import com.pswv2.bub.bsc.dao.po.KWord;
import com.pswv2.util.ExtraSpringHibernateTemplate;

@Service
public class KWordServiceImp implements KWordService {
	private static Class<?> poc = KWord.class;
	@Autowired
	private ExtraSpringHibernateTemplate extraSpringHibernateTemplate;
	@Override
	public void add(KWord kWord) {
		// TODO Auto-generated method stub
		extraSpringHibernateTemplate.getHibernateTemplate().save(kWord);
	}

	@Override
	public KWord queryById(int id) {
		// TODO Auto-generated method stub
		return extraSpringHibernateTemplate.findFirstOneByPropEq(poc, "kwordId", id);
	}

	@Override
	public void updata(KWord kWord) {
		// TODO Auto-generated method stub
		extraSpringHibernateTemplate.getHibernateTemplate().update(kWord);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<KWord> queryAll() {
		// TODO Auto-generated method stub
		return (List<KWord>) extraSpringHibernateTemplate.findAll(poc);
	}
	
	@Override
	public List<KWord> queryNotRecycleAll(int userId) {
		// TODO Auto-generated method stub
		return (List<KWord>) extraSpringHibernateTemplate.getHibernateTemplate().find("From KWord where userId=? and status!=3",userId);
	}
	@Override
	public List<KWord> queryInRecycleAll(int userId) {
		// TODO Auto-generated method stub
		return (List<KWord>) extraSpringHibernateTemplate.getHibernateTemplate().find("From KWord where userId=? and status=3",userId);
	}
	@Override
	public List<KWord> queryAllUser(int userId) {
		// TODO Auto-generated method stub
		return (List<KWord>) extraSpringHibernateTemplate.getHibernateTemplate().find("From KWord where userId=?",userId);
	}

	@Override
	public KWord queryByName(String name,Integer userId) {
		
		List<KWord> roles=(List<KWord>) extraSpringHibernateTemplate.getHibernateTemplate().find("From KWord where name=? and userId=?", name,userId);
		if(roles.size()>0){
			return  roles.get(0);
		}
		return null;
	}
}
